
#include<fstream>
#include <iostream>
#include<string>
#include<map>
using namespace std;
void getparam(string& json, map<string, string>& Map) {
	long long len = json.size(), i = 0;
	int photolen = 0,count=0;
	int pos_1 = 0, pos_2 = 0;
	//cout << json << endl;
	string key, value;
	string length = "length";
	while (pos_1 != len)
	{
		if (json[pos_1] == '"')
		{
			pos_2 = pos_1 + 1;
			while (json[pos_2] != '"')
			{
				pos_2++;
			}
			if(json[pos_2] == '"')
			{
				if(count % 2 != 1)
				{
					value = json.substr(pos_1 + 1, pos_2 - pos_1 - 1);
					
					//cout <<"value:  "<< value << endl;
				}
			else
				{
					key = "";
					if (value == "photo")
					{
						key.append(json, pos_1+1, photolen);
						//key= json.substr(pos_1 + 1, pos_1 + 1+photolen);
					}
					else
					key = json.substr(pos_1 + 1, pos_2 - pos_1 - 1);
					//cout <<"key:  "<< key << endl;
					if (value == length)
					{
						photolen = atoi(key.c_str());
						//cout << "------photolen:" << photolen << endl;
					}
				}
				count++;
				pos_1 = pos_2 + 1;
				pos_2 += 1;
			}
			if (count % 2 == 0)
			{
				Map.insert(map<string, string>::value_type(value, key));
			}
			if(value=="photo"&&count%2==0)
			break;
		}
		pos_1++;
	}
	//cout<<"------------------------"<<endl;
	//输出测试
	map<string, string>::iterator iter;
	iter = Map.begin();
	while (iter != Map.end())
	{
		cout << iter->first << ":" << iter->second << endl;
		iter++;
	}
	return;
}
int main()
{
	//cout << "\"";
	map<string, string> Map;
	string str3;// "{\"name\":\"狗屎丸子\",\"sid\" : \"27\",\"hot\" : \"122\",\"minet\" : \"11\",\"length\" : \"18\",\"photo\" : \"1&28\"3 - 6. & 8 \0¥ - 000\"}";
	str3.append("{\"name\":\"狗屎丸子\",\"sid\" : \"27\",\"hot\" : \"122\",\"minet\" : \"11\",\"length\" : \"26\",\"photo\" : \"1&28\"3 - 6. & 8 \\0¥ - 000\"}");
	//string str2 = "{\"ShopName\":\"烤鸡20个字1\",\"IsLogin\":\"1\",\"photopath\":\"/Datec/_28/28.jpg\",\"text\":\"测试信息为30个字1\",\"addr\":\"位置40个字1\",\"PhoneNumber\":\"1008611\",\"shoper\":\"李s1\",\"shoptyp\":\"1\",\"fdstype\":\"2\"}";
	//string str = " {\"ShopName\":\"可口可乐\",\"IsLogin\":\"1\",\"photopath\":\" / Datec / _27 / 27.jpg\",\"text\":\"这是这个商店的测试信息\",\"addr\":\"成都东软学院新食堂2楼笑笑笑笑笑包子\",\"PhoneNumber\":\"08161111111\",\"shoper\":\"张三\",\"shoptyp\":\"1\",\"fdstype\":\"1\"}";
	getparam(str3, Map);
	//getparam(str2, Map);
	//cout << str3;
	return 0;
}


